package com.yc.baseapi;

import cn.hutool.core.util.RandomUtil;

import java.util.Random;

public class TestRandom {
	
	public static void m1() {
		Random rm = new Random();
		System.out.println(rm.nextInt(3));
		
	}

	/**
	 * 随机产生1 或者 2
	 */
	public void m2() {
		long st = System.currentTimeMillis();
		for (int i = 0; i < 100000; i++) {
			System.out.println(Integer.valueOf(((System.currentTimeMillis()%2)+1)+""));
		}
		long et = System.currentTimeMillis();
		System.out.println(et-st);//241
	}

	public void m3() {
		long st = System.currentTimeMillis();
		for (int i = 0; i < 100000; i++) {
			System.out.println(RandomUtil.randomInt(1, 3));
		}
		long et = System.currentTimeMillis();
		System.out.println(et-st);//278
	}

	public static void main(String[] args) {
		TestRandom tr = new TestRandom();
//		TestRandom.m1();
//		tr.m2();
		tr.m3();
	}

}
